package com.ulic.customerManApplication.util.job;

import java.text.ParseException;
import java.util.Date;
import java.util.Formatter;

import org.apache.log4j.Logger;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;

/**
 * Description: 绩效评价job工具类
 * 北京中科汇联信息技术有限公司.
 * All Rights Reserved.
 * @version 1.0  
 * 2011-7-25 下午01:36:08 李求智 (liqz@huilan.com) created
 */
public class JobUtils {
	private static Logger logger = Logger.getLogger(JobUtils.class);
	public static Scheduler sched = null;
	static {
		SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();
		try {
			sched = schedFact.getScheduler();
			sched.start();
			if(logger.isDebugEnabled()){
				logger.debug("==============================");
				logger.debug("sched start.......");
				logger.debug("==============================");
			}
		} catch (SchedulerException e) {
			e.printStackTrace();
		}

	}
	
	/**
	 * Description: 启动加载机构树Job
	 * @Version1.0 
	 * 2011-7-25 下午01:38:36 李求智 (liqz@huilan.com) 创建
	 */
	@SuppressWarnings("deprecation")
	public static void startChangeSurveyStateJob(){
		try {
			JobDetail reloadJobDetail = new JobDetail("organTreeJob", "jobGroup", ReloadOrganizationTreeJob.class);
			//每天零点执行
			CronTrigger reloadTrigger = new CronTrigger();
			Formatter f = new Formatter();
			f.format("%s %s %s * * ?", 00, 00, 00);
			reloadTrigger.setCronExpression(f.toString());
			Date startTime = new Date();
			//startTime.setHours(23);
			reloadTrigger.setStartTime(startTime);
			reloadTrigger.setName("oragnTreeTrigger");
			reloadTrigger.setGroup("jobGroup");
			sched.scheduleJob(reloadJobDetail, reloadTrigger);
			logger.debug("ReloadOrganizationTreeJob started");
		}  catch (SchedulerException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
}
